<?php
ob_start();
require_once '../sub/init.php';
require_once 'chkUadm.php';
if(!in_array('u_qianxian',$QXARR) && !CRM_ADM)exit(noauth());
require_once ZEAI.'cache/udata.php';
require_once ZEAI.'cache/config_vip.php';
require_once ZEAI.'sub/ZeaiUP.php';
$qxflagARR = json_decode($_CRM['qxflag'],true);
switch ($submitok) {
	case"qx_bz_update":
		$id=intval($id);
		if($flag!=2 && $flag!=-1)json_exit(array('flag'=>0,'msg'=>'zeaierror:flag'));
		$bz = trimhtml(dataIO($content,'in'));
		if (str_len($bz) > 500)json_exit(array('flag'=>0,'msg'=>'内容字太多不要超过500字节'));
		$row = $db->ROW(__TBL_QIANXIAN__,"uid,senduid,flag,bz,pathlist","id=".$id,'num');
		if($row){
			$uid= $row[0];$senduid= $row[1];$flagoldstr= trimhtml(crm_arr_title($qxflagARR,$row[2]));$bzold= trimhtml($row[3]);$data_pathlist= $row[4];
		}else{
			json_exit(array('flag'=>0,'msg'=>'牵线记录不存在哦'));
		}
		$pathlist = tmp_piclist_modupdate($pathlist,$data_pathlist,'crm');
		$db->query("UPDATE ".__TBL_QIANXIAN__." SET bz='$bz',flag=$flag,pathlist='$pathlist' WHERE id=".$id);//flag!=2 AND 
		sea_mod_time($uid);
		sea_mod_time($senduid);
		$row2 = $db->ROW(__TBL_USER__,"nickname","id=".$uid,'num');$nickname= $row2[0];
		$row2 = $db->ROW(__TBL_USER__,"nickname","id=".$senduid,'num');$sendnickname= $row2[0];
		$uid_ = $uid;$uid=$senduid;
		AddLog('【牵线管理】操作牵线【'.$sendnickname.'（uid:'.$senduid.'）】->【'.$nickname.'（uid:'.$uid_.'）】原状态：'.$flagoldstr.'->新状态：'.trimhtml(crm_arr_title($qxflagARR,$flag)).'；原备注：'.$bzold.'->新备注：'.$bz);
		json_exit(array('flag'=>1,'msg'=>'操作成功'));
	break;
}
$sex_ARR  = json_decode($_UDATA['sex'],true);$extifshow = json_decode($_UDATA['extifshow'],true);
$mate_diy = explode(',',$_ZEAI['mate_diy']);
$qianxian_num = json_decode($_VIP['qianxian_num'],true);
$t=trimhtml($t);
$nav='index';
require_once ZEAI.'m/div_left_so.php';?>
<!doctype html><html><head><meta charset="utf-8">
<title><?php echo $_ADM['admSiteName']; ?></title>
<?php echo HEADMETA; ?>
<script src="<?php echo RES;?>www_zeai_cn.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/m.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<script src="<?php echo RES;?>m/js/ZeaiUP.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<link href="<?php echo RES;?>m/css/m.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<?php require_once 'm_style.php';?>
<link href="css/m_adm.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<style>
.ZEAI_list{padding:125px 0 80px;width:92%;margin:0 auto}
.ZEAI_list dl{width:100%;margin:0 auto 20px auto;border-radius:8px;background-color:#fff;box-shadow:0 0 28px rgb(0 0 0 / 8%);position:relative;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;position:relative}
.ZEAI_list dl .tbody{padding:0 10px;margin:0 auto 10px auto;line-height:40px;color:#999;border-bottom:#f5f5f5 1px solid;text-align:left}
.ZEAI_list dl .tbody .hninfo{float:right;color:#333}
.ZEAI_list dl .tbody .hninfo font{color:#999}

.ZEAI_list dl ul{width:100%;margin:12px auto;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.ZEAI_list dl ul li{width:33%;float:left;position:relative;text-align:center;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}
.ZEAI_list dl ul li img.s{width:50px;height:50px;border-radius:50%;object-fit:cover;-webkit-object-fit:cover}
.ZEAI_list dl ul li em font{color:#333;display:inline-block;vertical-align:middle}
.ZEAI_list dl ul li:nth-child(2) h6{margin-top:10px;color:#888;font-size:13px}
.ZEAI_list dl ul li:nth-child(2) i{color:#ccc;font-size:22px}
.ZEAI_list dl ul li:nth-child(2) span{display:block;font-size:14px}

.ZEAI_list dl .ubtnbox{border-top:#f5f5f5 1px solid;padding:5px 0 10px;text-align:right}
.ZEAI_list dl .ubtnbox .btn{margin:5px 10px 0 0;padding:0 8px}
.ZEAI_list dl .ubtnbox .sendkind{float:left;margin:10px 0 0 10px}

.listbottombox .qxnum{display:inline-block;margin-top:5px}
.listbottombox .qxnum b{color:#f00;font-weight:normal;margin:0 2px}

.tabmenufix {top:72px;}

.utopinfo {width:100vw;height:22px;line-height:14px;background-color:#fff;position:fixed;top:50px;left:0;color:#333;font-size:12px;z-index:3}
.utopinfo em{display:inline-block;vertical-align:middle}
.utopinfo span{color:#999;vertical-align:middle}
/*GYLform*/
#GYLform{width:100%;margin:20px auto 0 auto;text-align:left}
#GYLform dl{width:88%;margin:20px auto}
#GYLform dt{font-size:14px;color:<?php echo $_ADM['color'];?>}
#GYLform dd{margin-top:10px}
#GYLform .textarea{padding:5px}
</style>
</head><body>
<?php
if ($submitok == 'qx_bz'){
	$id=intval($id);
	$row = $db->ROW(__TBL_QIANXIAN__,"bz,pathlist","id=".$id,'num');
	if($row){$bz = dataIO($row[0],'out');$pathlist = trimhtml($row[1]);}?>
	<form id="GYLform">
    <dl>
        <dt>牵线内容<font class="Cf00">*</font></dt>
        <dd>
            <textarea name="content" rows="5" class="textarea W100_" id="content" placeholder="请输入牵线结果或过程进行存档&#13;&#13;如：【已电话或微信沟通互换了联系方式】，【双方还是比较满意的，会抽时间双方见个面】等"><?php echo $bz;?></textarea>
        </dd>
    </dl>
    <div class="clear"></div>
    <dl>
        <dt>牵线截图<font class="S12 C999">（支持批量上传）</font></dt>
        <dd class="piclibox" id="piclibox">
            <ul><li class="ico">&#xe622;</li>
            <?php
			if(!empty($pathlist)){
				$ARR=explode(',',$pathlist);
				if (count($ARR) >= 1 && is_array($ARR)){foreach ($ARR as $V){echo '<li><img src="'.UP.$V.'"><b></b></li>';}}//><b class="ico">&#xe62c;</b>
			}
            ?>
            </ul>
        </dd>
    </dl>
    <input type="hidden" name="flag" value="<?php echo $flag;?>" />
    <input type="hidden" name="id" value="<?php echo $id;?>" />
    <input type="hidden" name="submitok" value="qx_bz_update" />
    <input name="pathlist" id="piclist" type="hidden" value="<?php echo $pathlist;?>" />
    <div class="savebtnbox"><button type="button" class="btn size3 zeaibg" id="save">提交保存</button></div>
	</form>
	<script>
	var up2='<?php echo UP;?>',upMaxMB=<?php echo $_UP['upMaxMB']; ?>,maxnum=5,upurl='m_qianxian'+zeai.ajxext+'id=<?php echo $id;?>',browser='<?php echo browser();?>';
	save.onclick=function(){
		if (zeai.empty(o('content').value)){
			zeai.msg('请输入【牵线内容】'+o('content').value,o('content'));	
			return false;
		}
		zeai.ajax({url:'m_qianxian'+zeai.extname,form:GYLform},function(e){var rs=zeai.jsoneval(e);
			window.parent.zeai.msg(rs.msg);
			if(rs.flag==1){setTimeout(function(){window.parent.location.reload(true);},1000);}
		});
	}
	top.upurl='m_qianxian'+zeai.ajxext+'id=<?php echo $id;?>';//ifrmae 重置变量
	ZeaiUP.more({wxtmp:false,obj:piclibox,submitokBef:'ajax_tmpB_',end:function(e){/**/}});
	ZeaiUP.more_mod_init({libox:piclibox,formobj:o('piclist')});
	</script>
	<?php
exit;}?>

<?php
/****************************************UID信息*****************************************/
if ( !ifint($uid))alert_adm("用户UID不正确","back");
$row = $db->ROW(__TBL_USER__,"*","id=".$uid);
if(!$row)alert_adm("UID输入有误或不存在此会员","back");
$Utruename = dataIO($row['truename'],'out');
$Unickname = trimhtml(dataIO($row['nickname'],'out'));
$Usex   = $row['sex'];
$Ugrade = $row['grade'];
$Uphoto_s= $row['photo_s'];
$Ucrm_qxnum = $row['crm_qxnum'];
$Ucrm_yjnum = $row['crm_yjnum'];
//
$Uphoto_m_url = (!empty($Uphoto_s))?UP.smb($Uphoto_s,'m'):RES.'photo_m'.$Usex.'.png';
$Unickname = (empty($Unickname))?$Utruename:$Unickname;
$Uqxneednum=$Ucrm_qxnum;
$Uqxnum2 = $db->COUNT(__TBL_QIANXIAN__,"flag=2 AND (uid=".$uid." OR senduid=".$uid.")");
/****************************************UID信息 结束*************************************/
/****************************************SQL 开始*****************************************/
$SQL  = "b.kind<>4";
$SQL .= " AND b.crm_flag<>3 ";

$SQL .= ($ifwelcome=='hnid2' && !CRM_ADM)?" AND b.admid>0 AND b.hnid2=".$session_uid:"";

//我的
if($ifmy==1)$SQL .= " AND (a.admid=".$session_uid." )";//归属直接查牵线表了，不找主板故 OR b.hnid=".$session_uid." OR b.hnid2=".$session_uid."
if($ifonline==1)$SQL .= " AND a.admid=".$session_uid;//(b.admid=".$session_uid." OR b.hnid=".$session_uid." OR b.hnid2=".$session_uid." )

//非超管门店+地区 
$SQL .= getAgentSQL('b');

$Skey = trimhtml($Skey);
$Skey2 = trimhtml($Skey2);
if (ifint($Skey)){
	$SQL .= " AND (b.id=$Skey OR a.uid=$Skey) ";
}elseif(!empty($Skey)){
	$SQL .= " AND ( ( b.uname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".$Skey."%' ) OR ( b.nickname LIKE '%".urlencode($Skey)."%' ) )";
}

if (ifint($Skey2)){
	$SQL .= " AND a.admid=$Skey2 ";
}elseif(!empty($Skey2)){
	$SQL .= " AND (  a.admname LIKE '%".$Skey2."%' )";
}
if(!empty($sDATE1)){
	$sDATE1 = strtotime($sDATE1.' 00:00:01');
	$SQL .= " AND ( a.addtime >= '$sDATE1' )";
}
if(!empty($sDATE2)){
	$sDATE2 = strtotime($sDATE2.' 23:59:59');
	$SQL .= " AND ( a.addtime <= '$sDATE2' )";
}
if (ifint($qxflag) || $qxflag==-1)$SQL .= " AND a.flag = $qxflag ";
if (ifint($sendkindd))$SQL .= " AND a.sendkind = $sendkindd ";
if (ifint($uid)){
	$SQL .= " AND (a.senduid=$uid OR a.uid=$uid) ";
	$_ADM['admPageSize']=8;
}
if (ifint($sexx))$SQL .= " AND b.sex=$sexx ";
$SORT = " ORDER BY a.id DESC ";
/*************************************  SQL结束 ********************************************/
$mini_title ='<img src="'.$Uphoto_m_url.'" class="photo_s_iframeC">';
$mini_class='top_mini4 ';
$miniurl='m_crm_user.php?p='.intval($b);
$mini_L = '<em onClick="zeai.openurl(\''.$miniurl.'\')"><i class="ico" >&#xeaca;</i><span></span></em>';
require_once ZEAI.'m/top_mini.php';?>
<a class="so" id="user_search"><i class="ico">&#xe66c;</i><span>筛选</span></a>
<div class="utopinfo"><?php echo uicon($Usex.$Ugrade);?><em><?php echo $uid;?></em><span><?php echo '（'.$Unickname.'）';?></span></div>
<div class="tabmenu tabmenu3 tabmenufix">
	<a href="m_qianxian.php?uid=<?php echo $uid;?>&b=<?php echo $b;?>&t=<?php echo $t;?>&hyk=<?php echo $hyk;?>" class="ed">牵线列表</a>
	<a href="m_qianxian_select.php?uid=<?php echo $uid;?>&b=<?php echo $b;?>&t=<?php echo $t;?>&hyk=<?php echo $hyk;?>">选择牵线对象</a>
	<a id="user_search2">按条件筛选</a>
</div>
<form id="www_zeai_cn_FORM" class="ZEAI_list" method="get" action="<?php echo SELF; ?>">
	<?php
	$rt = $db->query("SELECT a.*,b.sex,b.grade,b.nickname,b.weixin,b.mob,b.photo_s FROM ".__TBL_QIANXIAN__." a,".__TBL_USER__." b WHERE ".$SQL." AND a.senduid=b.id ".$SORT." LIMIT ".$_ADM['admLimit']);
	$total = $db->num_rows($rt);
	if ($total <= 0 ) {
		echo "<div class='nodataico'><i class='ico'>&#xe608;</i>暂无信息<br><br><a class='aBAI' href='javascript:history.back(-1)'>返回上一步</a></div>";
	} else {
		$page_skin=2;$pagemode='mob';$pagesize=8;require_once ZEAI.'sub/page.php';
		$qxflagARR = json_decode($_CRM['qxflag'],true);
		for($i=1;$i<=$pagesize;$i++) {
			$rows = $db->fetch_array($rt,'name');if(!$rows) break;
            $id = $rows['id'];$uidd = $rows['uid'];
            $admid = $rows['admid'];
            $admname = dataIO($rows['admname'],'out');
            $sendnickname = trimhtml(dataIO($rows['nickname'],'out'));
            $sex     = $rows['sex'];
            $grade   = $rows['grade'];
            $bz      = $rows['bz'];
            $flag    = $rows['flag'];
            $senduid = $rows['senduid'];
            $sendkind = $rows['sendkind'];
            $addtime = YmdHis($rows['addtime'],'YmdHi');
            $photo_s = $rows['photo_s'];
            $mob = dataIO($rows['mob'],'out');
            $weixin = dataIO($rows['weixin'],'out');
            $bz = dataIO($rows['bz'],'out');
            $pathlist = $rows['pathlist'];
            if(!empty($photo_s)){
                $photo_s_url = UP.$photo_s;
                $photo_s_str = '<img src="'.$photo_s_url.'" class="photo_s">';
            }else{
                $photo_s_url = RES.'photo_s'.$sex.'.png';
                $photo_s_str = '<img src="'.$photo_s_url.'" class="photo_s">';
            }
            //
            $row2 = $db->ROW(__TBL_USER__,"sex,grade,nickname,photo_s,weixin,mob","id=".$uidd,"name");
            if ($row2){
                $sex2      = $row2['sex'];
                $grade2    = $row2['grade'];
                $photo_s2  = $row2['photo_s'];
                $nickname2 = trimhtml(dataIO($row2['nickname'],'out'));
                $mob2      = dataIO($row2['mob'],'out');
                $weixin2   = dataIO($row2['weixin'],'out');
                if(!empty($photo_s2)){
                    $photo_s_url2 = UP.$photo_s2;
                    $photo_s_str2 = '<img src="'.$photo_s_url2.'" class="photo_s">';
                }else{
                    $photo_s_url2 = RES.'photo_s'.$sex2.'.png';
                    $photo_s_str2 = '<img src="'.$photo_s_url2.'" class="photo_s">';
                }
            }
			$flagT = crm_arr_title($qxflagARR,$flag);
			?>
            <dl id="tr<?php echo $id;?>">
            	<div class="tbody">
                	<input type="checkbox" name="list[]" value="<?php echo $id; ?>" uid="<?php echo $uidd; ?>" id="id<?php echo $id; ?>" class="checkskin"><label for="id<?php echo $id; ?>" class="checkskin-label"><i class="i1"></i></label>
                    <div class="hninfo"><font>牵线人：</font><?php echo $admname.' ID:'.$admid;?></div>
				</div>
				<ul>
                    <li onClick="zeai.openurl('<?php echo mHref('crm_u',$senduid);?>')"><img src="<?php echo $photo_s_url;?>" class="s"><em><?php echo uicon($sex.$grade);?><font class="S14"><?php echo $senduid;?></font><div class="C999"><?php echo $sendnickname;?></div></em></li>
                    <li><h6><?php echo $addtime;?></h6><i class="ico">&#xe62d;</i><span><?php echo $flagT;?></span></li>
                    <li onClick="zeai.openurl('<?php echo mHref('crm_u',$uidd);?>')"><img src="<?php echo $photo_s_url2;?>" class="s"><em><?php echo uicon($sex2.$grade2);?><font class="S14"><?php echo $uidd;?></font><div class="C999"><?php echo $nickname2;?></div></em></li>
					<div class="clear"></div>
                </ul>
                <div class="clear"></div>
                <div class="ubtnbox">
                	<span class="sendkind"><font class="C999">发起牵线：</font><?php echo ($sendkind == 1)?'用户主动':'红娘主动';?></span>
                    <?php if($flag != 2){?>
                        <a href="javascript:;" class="btn size2 BAI flag" flag="-1" qxid="<?php echo $id;?>" title2="<?php echo urlencode($senduid.'<font>|</font>'.$sendnickname);?>">牵线失败</a>
                        <a href="javascript:;" class="btn size2 zeaibg flag" flag="2" qxid="<?php echo $id;?>" title2="<?php echo urlencode($senduid.'<font>|</font>'.$sendnickname);?>" photo_s_url="<?php echo $photo_s_url2;?>">牵线成功</a>
                    <?php }?>
                    <div class="clear"></div>
                </div>
            </dl>
			<?php
		}
	}
	?>
</form>
<script>var bg = '<?php echo $_Style['list_bg']; ?>',overbg = '<?php echo $_Style['list_overbg']; ?>',selectbg = '<?php echo $_Style['list_selectbg']; ?>';</script>
<!--div_left_so-->
<div id="rangebox"></div>
<div class="div_left_so" id="user_so">
	<form action="<?php echo SELF;?>" method="get" name="www.yzlove.com" id="ZEAI_CN_FORM_ext">
    	<div class="form_uid">
        <input name="Skey" type="text" class="input" id="Skey" maxlength="20" value="<?php echo $Skey;?>" placeholder="按用户UID/用户名/昵称" autocomplete="off">
        <button type="submit" class="ico">&#xe6c4;</button>
		</div>
    	<div class="form_uid">
        <input name="Skey2" type="text" class="input" id="Skey2" maxlength="20" value="<?php echo $Skey2;?>" placeholder="按红娘ID/姓名" autocomplete="off">
        <button type="submit" class="ico">&#xe6c4;</button>
		</div>
        <?php
		div_left_so_out(array('tbody'=>'牵线状态','t'=>'qxflag','tv'=>$qxflag,'subkind'=>2,'newarr'=>json_decode($_CRM['qxflag']),'ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'发起牵线','t'=>'sendkindd','tv'=>$sendkindd,'subkind'=>2,'newarr'=>json_decode('[{"i":"1","v":"用户主动"},{"i":"2","v":"红娘主动"}]'),'ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'主动方性别','t'=>'sexx','tv'=>$sexx,'subkind'=>2,'newarr'=>json_decode($_UDATA['sex']),'ulcls'=>' col3'));
		div_left_so_out(array('tbody'=>'我牵的','t'=>'ifmy','tv'=>$ifmy,'subkind'=>2,'newarr'=>json_decode('[{"i":"1","v":"用户主动"}]'),'ulcls'=>' col3'));
		?>
        <script>div_left_so_init('user_so')</script>
        <div class="savebox"><button type="button" class="btn size3 reset" onClick="div_left_so_reset('user_so',['t','b','uid'])">重置</button><button type="submit" class="btn size3 zeaibg ico">&#xe6c4; 确定</button></div>
        <input type="hidden" name="t" id="t" value="<?php echo $t;?>" />
        <input type="hidden" name="b" id="b" value="<?php echo $b;?>" />
        <input type="hidden" name="hyk" id="hyk" value="<?php echo $hyk;?>" />
        <input type="hidden" name="uid" id="uid" value="<?php echo $uid;?>" />
    </form>
</div>
<script>
user_search.onclick=user_searchFn;
user_search2.onclick=user_searchFn;
function user_searchFn(){ZeaiM.div_left({obj:user_so,w:28});}
</script>
<!--div_left_so end-->
<?php if ($total > 0 ){?>
    <?php echo $page_cls;?>
    <div class="listbottombox">
        <div class="qxnum">需成功<b><?php echo $Uqxneednum;?></b>次，当前<b><?php echo $Uqxnum2;?></b>次</div>
        <?php if ($total > $pagesize)echo '<div class="pagebox">'.$pagelist.'</div>'; ?>
    </div>
    <div id="backtop"><a id="btmTopBtn"><i class="ico">&#xe60c;</i>顶部</a></div>
    <script>
    document.body.onscroll = backtop_alone;
	zeai.listEach('.flag',function(obj){
		if(!obj.hasClass('disabled'))obj.onclick = function(){
			var id = parseInt(obj.getAttribute("qxid")),
			flag = parseInt(obj.getAttribute("flag")),
			title2 = obj.getAttribute("title2");
			var photo_s_url = decodeURIComponent(obj.getAttribute("photo_s_url"));
			var photo_s_iframeL = (!zeai.empty(photo_s_url))?'<img src="'+photo_s_url+'" class="photo_s_iframeL">':'';
			str = (flag==2)?'确定牵线成功？<br><br>牵线成功将在前台相关页面展示牵线成功信息，如：XXX和XXX牵线成功！':'确定牵线失败？';
			zeai.confirm(str,function(){
				ZeaiM.iframe({title:photo_s_iframeL+'<span>【'+title2+'】跟进管理</span>',url:'m_qianxian.php?submitok=qx_bz&flag='+flag+'&id='+id});
			});
		}
	});
    </script>
    <script src="js/zeai_tablelist.js?<?php echo $_ZEAI['cache_str'];?>"></script>
<?php }?>
</body></html><?php ob_end_flush();?>